﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Library;

namespace OA.Exam
{
    public partial class PapersMaintain : System.Web.UI.Page
    {
        Exam myExam = new Exam();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request["paperId"] != null)
                {
                    HiddenMark.Value = "edit";
                    string paperId = Request["paperId"].ToString();
                    TxtPaperName.Text = myExam.GetRecordOfPaper(paperId).Rows[0]["papername"].ToString();
                    //TxtScore.Text = myExam.GetRecordOfPaper(paperId).Rows[0]["Score"].ToString();
                    TxtDes.Text = myExam.GetRecordOfPaper(paperId).Rows[0]["description"].ToString();
                    TxtExamTime.Text = myExam.GetRecordOfPaper(paperId).Rows[0]["examtime"].ToString();
                }
            }
        }
        //返回
        protected void BtnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("PapersManage.aspx");
        }
        //保存
        protected void BtnSave_Click(object sender, EventArgs e)
        {
            string paperName = TxtPaperName.Text.Trim();
            string description = TxtDes.Text.Trim();
            int score = 0;
            int examTime = int.Parse(TxtExamTime.Text.Trim());

            if (HiddenMark.Value == "edit")//修改
            {
                string paperId = Request["paperId"].ToString();
                if (myExam.UpdatePaper(paperId, paperName, score, "1", description, examTime))
                {
                    Response.Redirect("SetPaperQuestions.aspx?paperId=" + paperId);
                }
                else
                {
                    LabPrompt.Text = "保存失败";
                }

            }
            else //新增
            {
                string paperId = SqlUtil.GetPrimaryKeyId();

                if (myExam.InsertPaper(paperId, paperName, score, "1", description, examTime))
                {
                    Response.Redirect("SetPaperQuestions.aspx?paperId=" + paperId);
                }
                else
                {
                    LabPrompt.Text = "保存失败";
                }
            }
        }
    }
}
